package com.zygh.policeasset.service;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.mapper.*;
import com.zygh.policeasset.pojo.*;
import com.zygh.policeasset.pojo.vo.AssetsCheckUpdateVO;
import com.zygh.policeasset.pojo.vo.AuditFlowTODoVO;
import com.zygh.policeasset.pojo.vo.QrCodeGeneratedVO;
import com.zygh.policeasset.pojo.vo.RepairVO;
import com.zygh.policeasset.utils.AuditUtil;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.StringUtils;

@Service
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/service/AuditFlowService.class */
public class AuditFlowService {
    @Autowired
    AuditFlowMapper auditFlowMapper;
    @Autowired
    AuditFlowDetailMapper auditFlowDetailMapper;
    @Autowired
    ApprovalStepsMapper approvalStepsMapper;
    @Autowired
    UserMapper userMapper;
    @Autowired
    NoticeAfficheMapper noticeAfficheMapper;
    @Autowired
    SettlementMapper settlementMapper;
    @Autowired
    ProjectAssetsBusinessMapper projectAssetsBusinessMapper;
    @Autowired
    ProjectMapper projectMapper;
    @Autowired
    PurchaseAssetsBusinessMapper purchaseAssetsBusinessMapper;
    @Autowired
    SectionMapper sectionMapper;
    @Autowired
    DailyProjectMapper dailyProjectMapper;
    @Autowired
    QrCodeGeneratedMapper qrCodeGeneratedMapper;
    @Autowired
    RepairMapper repairMapper;

    @Autowired
    AssetsUpdateMapper assetsUpdateMapper;

    @Autowired
    AssetsMapper assetsMapper;

    @Autowired
    ImagesMapper imagesMapper;

    @Autowired
    AssetsCheckUpdateMapper assetsCheckUpdateMapper;

    @Autowired
    ApprovalUseContentMapper approvalUseContentMapper;

    /*  @Transactional(rollbackFor = {Exception.class})
      public CommonResult submitOrApproval(AuditDataDTO auditDataDTO) {
          Integer auditStatus;
          try {
              String user = this.approvalStepsMapper.approvedBy(auditDataDTO.getTableType());
              if (!StringUtils.isEmpty(user)) {
                  String[] users = user.split(",");
                  if (auditDataDTO.getProcessType().intValue() == 1) {
                      if ("project_assets_business".equals(auditDataDTO.getTableType()) && this.projectAssetsBusinessMapper.queryByFlowNo(auditDataDTO.getFlowNo()).intValue() == 0) {
                          return new CommonResult().validateFailed("请先录入资产再提交审批");
                      }
                      if ("purchase_assets_business".equals(auditDataDTO.getTableType()) && this.purchaseAssetsBusinessMapper.queryByFlowNo(auditDataDTO.getFlowNo()).intValue() == 0) {
                          return new CommonResult().validateFailed("请先录入资产再提交审批");
                      }
                      if ("daily_project".equals(auditDataDTO.getTableType()) && this.dailyProjectMapper.queryByFlowNo(auditDataDTO.getFlowNo()).intValue() == 0) {
                          return new CommonResult().validateFailed("请先录入资产再提交审批");
                      }
                      submit(auditDataDTO, users);
                  } else if (auditDataDTO.getProcessType().intValue() == 2) {
                      approval(auditDataDTO, users);
                  } else if (auditDataDTO.getProcessType().intValue() == 3) {
                      this.auditFlowMapper.updateAppStatus(new AuditFlow().setFlowNo(auditDataDTO.getFlowNo()).setAppStatus(4).setCreateTime(DateUtil.now()));
                      this.auditFlowDetailMapper.updateAuditStatus(new AuditFlowDetail().setFlowNo(auditDataDTO.getFlowNo()).setReviewer(auditDataDTO.getApplicant()).setRemark(auditDataDTO.getOpinion()).setAuditStatus(Integer.valueOf(AuditStatusEnum.UNDO.getIndex())).setSignatureUrl(auditDataDTO.getSignatureUrl()).setAuditTime(DateUtil.now()));
                      this.auditFlowDetailMapper.deleteByFlowNoAndId(auditDataDTO.getFlowNo(), 5);
                  } else if (auditDataDTO.getProcessType().intValue() == 4 || auditDataDTO.getProcessType().intValue() == 5) {
                      this.auditFlowDetailMapper.deleteByFlowNo(auditDataDTO.getFlowNo());
                      if ("project_assets_business".equals(auditDataDTO.getTableType()) && this.projectAssetsBusinessMapper.queryByFlowNo(auditDataDTO.getFlowNo()).intValue() == 0) {
                          return new CommonResult().validateFailed("请先录入资产再提交审批");
                      }
                      if ("purchase_assets_business".equals(auditDataDTO.getTableType()) && this.projectAssetsBusinessMapper.queryByFlowNo(auditDataDTO.getFlowNo()).intValue() == 0) {
                          return new CommonResult().validateFailed("请先录入资产再提交审批");
                      }
                      if ("daily_project".equals(auditDataDTO.getTableType()) && this.dailyProjectMapper.queryByFlowNo(auditDataDTO.getFlowNo()).intValue() == 0) {
                          return new CommonResult().validateFailed("请先录入资产再提交审批");
                      }
                      this.auditFlowMapper.updateAppStatus(new AuditFlow().setFlowNo(auditDataDTO.getFlowNo()).setAppStatus(1).setCreateTime(DateUtil.now()));
                      this.auditFlowDetailMapper.insert(new AuditFlowDetail().setFlowNo(auditDataDTO.getFlowNo()).setReviewer(auditDataDTO.getApplicant()).setAuditStatus(Integer.valueOf(AuditStatusEnum.SUBMIT.getIndex())).setAuditTime(DateUtil.now()).setSignatureUrl(auditDataDTO.getSignatureUrl()));
                      for (int i = 0; i < users.length; i++) {
                          if (i == 0) {
                              auditStatus = Integer.valueOf(AuditStatusEnum.FORMYAPPROVAL.getIndex());
                          } else {
                              auditStatus = Integer.valueOf(AuditStatusEnum.WAITAPPROVAL.getIndex());
                          }
                          this.auditFlowDetailMapper.insert(new AuditFlowDetail().setFlowNo(auditDataDTO.getFlowNo()).setReviewer(Integer.valueOf(Integer.parseInt(users[i]))).setAuditStatus(auditStatus));
                      }
                  }
              } else {
                  this.auditFlowMapper.updateAppStatus(new AuditFlow().setAppStatus(2).setFlowNo(auditDataDTO.getFlowNo()));
              }
              return new CommonResult().success();
          } catch (Exception e) {
              e.printStackTrace();
              TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
              return new CommonResult().validateFailed(e.toString());
          }
      }

      public void submit(AuditDataDTO auditDataDTO, String[] users) {
          Integer auditStatus;
          if (users.length > 0) {
              this.auditFlowMapper.updateAppStatus(new AuditFlow().setAppStatus(1).setFlowNo(auditDataDTO.getFlowNo()));
              this.auditFlowDetailMapper.insert(new AuditFlowDetail().setFlowNo(auditDataDTO.getFlowNo()).setReviewer(auditDataDTO.getApplicant()).setAuditStatus(Integer.valueOf(AuditStatusEnum.SUBMIT.getIndex())).setAuditTime(DateUtil.now()).setSignatureUrl(auditDataDTO.getSignatureUrl()));
              for (int i = 0; i < users.length; i++) {
                  if (i == 0) {
                      auditStatus = Integer.valueOf(AuditStatusEnum.FORMYAPPROVAL.getIndex());
                  } else {
                      auditStatus = Integer.valueOf(AuditStatusEnum.WAITAPPROVAL.getIndex());
                  }
                  System.out.println(users[i]);
                  this.auditFlowDetailMapper.insert(new AuditFlowDetail().setFlowNo(auditDataDTO.getFlowNo()).setReviewer(Integer.valueOf(Integer.parseInt(users[i]))).setAuditStatus(auditStatus));
              }
          }
      }

      public void approval(AuditDataDTO auditDataDTO, String[] users) {
          Project project;
          if ("repair_zn".equals(auditDataDTO.getTableType()) || "repair_jc".equals(auditDataDTO.getTableType())) {
              this.repairMapper.issued(auditDataDTO.getOrderUserId(), auditDataDTO.getFlowNo());
          }
          if (auditDataDTO.getAppStatus().intValue() == 2) {
              Integer lastUserId = Integer.valueOf(Integer.parseInt(users[users.length - 1]));
              System.out.println(lastUserId);
              System.out.println(auditDataDTO.getApplicant());
              System.out.println(auditDataDTO.getApplicant() == lastUserId);
              if (auditDataDTO.getApplicant().equals(lastUserId)) {
                  System.out.println("是最后一个审批人");
                  this.auditFlowDetailMapper.updateAuditStatus(new AuditFlowDetail().setFlowNo(auditDataDTO.getFlowNo()).setReviewer(auditDataDTO.getApplicant()).setRemark(auditDataDTO.getOpinion()).setAuditStatus(Integer.valueOf(AuditStatusEnum.ADOPT.getIndex())).setSignatureUrl(auditDataDTO.getSignatureUrl()).setAuditTime(DateUtil.now()));
                  this.auditFlowMapper.updateAppStatus(new AuditFlow().setFlowNo(auditDataDTO.getFlowNo()).setAppStatus(2).setCreateTime(DateUtil.now()));
                  Integer userId = this.auditFlowMapper.queryAll(new AuditFlow().setFlowNo(auditDataDTO.getFlowNo())).get(0).getApplicant();
                  if ("settlement".equals(auditDataDTO.getTableType())) {
                      String now = DateUtil.now();
                      String flowNo = AuditUtil.getFlowNo(now);
                      Settlement settlement = this.settlementMapper.selectIdByFlowNo(auditDataDTO.getFlowNo());
                      this.projectAssetsBusinessMapper.insert(settlement.getId(), flowNo);
                      add(userId, flowNo, now, TableType.PROJECTASSETSBUSINESS.getName(), TableType.PROJECTASSETSBUSINESS.getType(), settlement.getProjectNo(), Integer.valueOf(Integer.parseInt(settlement.getSectionId())));
                  } else if ("project".equals(auditDataDTO.getTableType()) && (project = this.projectMapper.selectIdByFlowNo(auditDataDTO.getFlowNo())) != null && project.getCategory() == 4 && project.getPid() != 0) {
                      String now2 = DateUtil.now();
                      String flowNo2 = AuditUtil.getFlowNo(now2);
                      this.purchaseAssetsBusinessMapper.insert(project.getId(), flowNo2);
                      add(userId, flowNo2, now2, TableType.PURCHASEASSETSBUSINESS.getName(), TableType.PURCHASEASSETSBUSINESS.getType(), project.getProjectNo(), null);
                  }
              } else {
                  System.out.println("不是最后一个审批人");
                  int j = 0;
                  int i = 0;
                  while (true) {
                      if (i >= users.length) {
                          break;
                      } else if (String.valueOf(auditDataDTO.getApplicant()).equals(users[i])) {
                          j = i;
                          break;
                      } else {
                          i++;
                      }
                  }
                  this.auditFlowDetailMapper.updateAuditStatus(new AuditFlowDetail().setFlowNo(auditDataDTO.getFlowNo()).setReviewer(auditDataDTO.getApplicant()).setRemark(auditDataDTO.getOpinion()).setAuditStatus(Integer.valueOf(AuditStatusEnum.ADOPT.getIndex())).setSignatureUrl(auditDataDTO.getSignatureUrl()).setAuditTime(DateUtil.now()));
                  this.auditFlowDetailMapper.updateAuditStatus(new AuditFlowDetail().setFlowNo(auditDataDTO.getFlowNo()).setReviewer(Integer.valueOf(Integer.parseInt(users[j + 1]))).setAuditStatus(Integer.valueOf(AuditStatusEnum.FORMYAPPROVAL.getIndex())));
              }
          } else if (auditDataDTO.getAppStatus().intValue() == 3) {
              this.auditFlowDetailMapper.updateAuditStatus(new AuditFlowDetail().setFlowNo(auditDataDTO.getFlowNo()).setReviewer(auditDataDTO.getApplicant()).setRemark(auditDataDTO.getOpinion()).setAuditStatus(Integer.valueOf(AuditStatusEnum.REFUSE.getIndex())).setSignatureUrl(auditDataDTO.getSignatureUrl()).setAuditTime(DateUtil.now()));
              this.auditFlowDetailMapper.deleteByFlowNoAndId(auditDataDTO.getFlowNo(), 4);
              this.auditFlowMapper.updateAppStatus(new AuditFlow().setFlowNo(auditDataDTO.getFlowNo()).setAppStatus(3).setCreateTime(DateUtil.now()));
          }
      }

      public PageInfo queryAudit(int pageNum, int pageSize, Integer userId, Integer status, String tableType, Integer applicant) {
          String tableType1;
          PageHelper.startPage(pageNum, pageSize);
          List<AuditFlowTODoVO> list = this.auditFlowMapper.queryAudit(userId, status, tableType, applicant);
          for (AuditFlowTODoVO auditFlowTODoVO : list) {
              AuditFlow auditFlow = this.auditFlowMapper.queryById(auditFlowTODoVO.getId());
              if ("repair_jc".equals(auditFlow.getTableType()) || "repair_zn".equals(auditFlow.getTableType())) {
                  tableType1 = "repair";
              } else {
                  tableType1 = auditFlow.getTableType();
              }
              auditFlowTODoVO.setTableId(this.auditFlowMapper.queryIdByflowNo(tableType1, auditFlow.getFlowNo()));
              if (auditFlowTODoVO.getTableType().equals("project") || auditFlowTODoVO.getTableType().equals("tender") || auditFlowTODoVO.getTableType().equals("contract") || auditFlowTODoVO.getTableType().equals("completed") || auditFlowTODoVO.getTableType().equals("settlement") || auditFlowTODoVO.getTableType().equals("final_statement") || auditFlowTODoVO.getTableType().equals("unit_information") || auditFlowTODoVO.getTableType().equals("project_assets_business") || auditFlowTODoVO.getTableType().equals("purchase_assets_business")) {
                  auditFlowTODoVO.setProjectName(this.projectMapper.findByProjectNo(auditFlowTODoVO.getProjectNo()));
              }
              if (auditFlowTODoVO.getTableType().equals("contract") || auditFlowTODoVO.getTableType().equals("completed") || auditFlowTODoVO.getTableType().equals("settlement") || auditFlowTODoVO.getTableType().equals("final_statement") || auditFlowTODoVO.getTableType().equals("project_assets_business") || auditFlowTODoVO.getTableType().equals("purchase_assets_business")) {
                  Section section = this.sectionMapper.selectById(auditFlowTODoVO.getSectionId());
                  if (!StringUtils.isEmpty(section)) {
                      auditFlowTODoVO.setSectionName(section.getSectionName());
                  }
              }
              if (auditFlowTODoVO.getTableType().equals("qr_code_generated")) {
                  QrCodeGeneratedVO qrCodeGeneratedVO = this.qrCodeGeneratedMapper.selectByflowNo(auditFlow.getFlowNo());
                  if (!StringUtils.isEmpty(qrCodeGeneratedVO)) {
                      auditFlowTODoVO.setProjectName(qrCodeGeneratedVO.getBuildName());
                      auditFlowTODoVO.setSectionName(qrCodeGeneratedVO.getSectionName());
                  }
              }
              if (auditFlowTODoVO.getTableType().equals("daily_project") && !StringUtils.isEmpty(auditFlowTODoVO.getProjectNo())) {
                  DailyProject dailyProject = this.dailyProjectMapper.findById(Integer.valueOf(Integer.parseInt(auditFlowTODoVO.getProjectNo())));
                  if (!StringUtils.isEmpty(dailyProject)) {
                      auditFlowTODoVO.setProjectName(dailyProject.getProjectName());
                  }
              }
          }
          return new PageInfo(list);
      }
  */
    @Transactional(rollbackFor = {Exception.class})
    public CommonResult submitOrApproval(AuditDataDTO auditDataDTO) {
        Integer auditStatus;
        try {
            String user = this.approvalStepsMapper.approvedById(auditDataDTO.getApprovalStepsId());
            if (!StringUtils.isEmpty(user)) {
                String[] users = user.split(",");
                if (auditDataDTO.getProcessType().equals(1)) {
                    if ("project_assets_business".equals(auditDataDTO.getTableType()) &&
                            projectAssetsBusinessMapper.queryByFlowNo(auditDataDTO.getFlowNo()) == 0) {
                        return new CommonResult().validateFailed("请先录入资产再提交审批");
                    }
                    if ("purchase_assets_business".equals(auditDataDTO.getTableType()) &&
                            purchaseAssetsBusinessMapper.queryByFlowNo(auditDataDTO.getFlowNo()) == 0) {
                        return new CommonResult().validateFailed("请先录入资产再提交审批");
                    }
                    if ("daily_project".equals(auditDataDTO.getTableType()) &&
                            dailyProjectMapper.queryByFlowNo(auditDataDTO.getFlowNo()) == 0) {
                        return new CommonResult().validateFailed("请先录入资产再提交审批");
                    }
                    submit(auditDataDTO, users);
                } else if (auditDataDTO.getProcessType().equals(2)) {
                    approval(auditDataDTO, users);
                } else if (auditDataDTO.getProcessType().equals(3)) {
                    this.auditFlowMapper.updateAppStatus(new AuditFlow().setFlowNo(auditDataDTO.getFlowNo()).setAppStatus(4).setCreateTime(DateUtil.now()));
                    this.auditFlowDetailMapper.updateAuditStatus(new AuditFlowDetail().setFlowNo(auditDataDTO.getFlowNo()).setReviewer(auditDataDTO.getApplicant()).setRemark(auditDataDTO.getOpinion()).setAuditStatus(Integer.valueOf(AuditStatusEnum.UNDO.getIndex())).setSignatureUrl(auditDataDTO.getSignatureUrl()).setAuditTime(DateUtil.now()));
                    this.auditFlowDetailMapper.deleteByFlowNoAndId(auditDataDTO.getFlowNo(), 5);
                } else if (auditDataDTO.getProcessType().equals(4) || auditDataDTO.getProcessType().equals(5)) {
                    this.auditFlowDetailMapper.deleteByFlowNo(auditDataDTO.getFlowNo());
                    if ("project_assets_business".equals(auditDataDTO.getTableType()) &&
                            this.projectAssetsBusinessMapper.queryByFlowNo(auditDataDTO.getFlowNo()) == 0) {
                        return new CommonResult().validateFailed("请先录入资产再提交审批");
                    }
                    if ("purchase_assets_business".equals(auditDataDTO.getTableType()) &&
                            this.purchaseAssetsBusinessMapper.queryByFlowNo(auditDataDTO.getFlowNo()) == 0) {
                        return new CommonResult().validateFailed("请先录入资产再提交审批");
                    }
                    if ("daily_project".equals(auditDataDTO.getTableType()) &&
                            this.dailyProjectMapper.queryByFlowNo(auditDataDTO.getFlowNo()) == 0) {
                        return new CommonResult().validateFailed("请先录入资产再提交审批");
                    }
                    this.auditFlowMapper.updateAppStatus(new AuditFlow().setFlowNo(auditDataDTO.getFlowNo()).setAppStatus(1).setCreateTime(DateUtil.now()));
                    this.auditFlowDetailMapper.insert(new AuditFlowDetail().setFlowNo(auditDataDTO.getFlowNo()).setReviewer(auditDataDTO.getApplicant()).setAuditStatus(Integer.valueOf(AuditStatusEnum.SUBMIT.getIndex())).setAuditTime(DateUtil.now()).setSignatureUrl(auditDataDTO.getSignatureUrl()));
                    for (int i = 0; i < users.length; i++) {
                        if (i == 0) {
                            auditStatus = Integer.valueOf(AuditStatusEnum.FORMYAPPROVAL.getIndex());
                        } else {
                            auditStatus = Integer.valueOf(AuditStatusEnum.WAITAPPROVAL.getIndex());
                        }
                        this.auditFlowDetailMapper.insert(new AuditFlowDetail()
                                .setFlowNo(auditDataDTO.getFlowNo())
                                .setReviewer(Integer.valueOf(Integer.parseInt(users[i])))
                                .setAuditStatus(auditStatus));
                    }
                }
            } else {
                this.auditFlowMapper.updateAppStatus(new AuditFlow().setAppStatus(2).setFlowNo(auditDataDTO.getFlowNo()));
            }
            return new CommonResult().success();
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return new CommonResult().validateFailed(e.toString());
        }
    }

    public void submit(AuditDataDTO auditDataDTO, String[] users) {
        Integer auditStatus;
        if (users.length > 0) {
            this.auditFlowMapper.updateAppStatus(new AuditFlow()
                    .setAppStatus(1)
                    .setFlowNo(auditDataDTO.getFlowNo())
                    .setApprovalStepsId(auditDataDTO.getApprovalStepsId()));
            this.auditFlowDetailMapper.insert(new AuditFlowDetail().setFlowNo(auditDataDTO.getFlowNo()).setReviewer(auditDataDTO.getApplicant()).setAuditStatus(Integer.valueOf(AuditStatusEnum.SUBMIT.getIndex())).setAuditTime(DateUtil.now()).setSignatureUrl(auditDataDTO.getSignatureUrl()));
            for (int i = 0; i < users.length; i++) {
                if (i == 0) {
                    auditStatus = Integer.valueOf(AuditStatusEnum.FORMYAPPROVAL.getIndex());
                } else {
                    auditStatus = Integer.valueOf(AuditStatusEnum.WAITAPPROVAL.getIndex());
                }
                this.auditFlowDetailMapper.insert(new AuditFlowDetail().setFlowNo(auditDataDTO.getFlowNo()).setReviewer(Integer.valueOf(Integer.parseInt(users[i]))).setAuditStatus(auditStatus));
            }
        }
    }

    public void approval(AuditDataDTO auditDataDTO, String[] users) {
        Project project;
        if ("repair".equals(auditDataDTO.getTableType())) {
            this.repairMapper.issued(auditDataDTO.getOrderUserId(), auditDataDTO.getFlowNo());
        }
        if (auditDataDTO.getAppStatus().equals(2)) {
            Integer lastUserId = Integer.valueOf(Integer.parseInt(users[users.length - 1]));
            if (auditDataDTO.getApplicant().equals(lastUserId)) {
                System.out.println("是最后一个审批人");
                this.auditFlowDetailMapper.updateAuditStatus(new AuditFlowDetail()
                        .setFlowNo(auditDataDTO.getFlowNo())
                        .setReviewer(auditDataDTO.getApplicant())
                        .setRemark(auditDataDTO.getOpinion())
                        .setAuditStatus(Integer.valueOf(AuditStatusEnum.ADOPT.getIndex()))
                        .setSignatureUrl(auditDataDTO.getSignatureUrl()).setAuditTime(DateUtil.now()));
                this.auditFlowMapper.updateAppStatus(new AuditFlow()
                        .setFlowNo(auditDataDTO.getFlowNo())
                        .setAppStatus(2)
                        .setCreateTime(DateUtil.now())
                        .setApprovalStepsId(auditDataDTO.getApprovalStepsId()));
                Integer userId = this.auditFlowMapper.queryAll(new AuditFlow().setFlowNo(auditDataDTO.getFlowNo())).get(0).getApplicant();
                if ("settlement".equals(auditDataDTO.getTableType())) {
                    String now = DateUtil.now();
                    String flowNo = AuditUtil.getFlowNo(now);
                    Settlement settlement = this.settlementMapper.selectIdByFlowNo(auditDataDTO.getFlowNo());
                    this.projectAssetsBusinessMapper.insert(settlement.getId(), flowNo);
                    add(userId, flowNo, now, TableType.PROJECTASSETSBUSINESS.getName(), TableType.PROJECTASSETSBUSINESS.getType(), settlement.getProjectNo(), Integer.valueOf(Integer.parseInt(settlement.getSectionId())));
                } else if ("project".equals(auditDataDTO.getTableType()) && (project = this.projectMapper.selectIdByFlowNo(auditDataDTO.getFlowNo())) != null && project.getCategory() == 4 && project.getPid() != 0) {
                    String now2 = DateUtil.now();
                    String flowNo2 = AuditUtil.getFlowNo(now2);
                    this.purchaseAssetsBusinessMapper.insert(project.getId(), flowNo2);
                    add(userId, flowNo2, now2, TableType.PURCHASEASSETSBUSINESS.getName(), TableType.PURCHASEASSETSBUSINESS.getType(), project.getProjectNo(), null);
                } else if ("assets_update".equals(auditDataDTO.getTableType())) {
                    AssetsUpdate assetsUpdate = assetsUpdateMapper.findByIdFlowNo(auditDataDTO.getFlowNo());

                    Assets assets = new Assets();
                    assets.setId(assetsUpdate.getAssetId());
                    if (!StringUtils.isEmpty(assetsUpdate.getPlace())) {
                        assets.setPlace(assetsUpdate.getPlace());
                    }
                    if (!StringUtils.isEmpty(assetsUpdate.getUseUser())) {
                        assets.setUseUser(assetsUpdate.getUseUser());
                    }
                    assetsMapper.updateById(assets);
                    if (!StringUtils.isEmpty(assetsUpdate.getImageUrl())) {
                        imagesMapper.updateConnectByAssetsId(assetsUpdate.getImageUrl(), assetsUpdate.getAssetId());
                    }
                } else if ("assets_check_update".equals(auditDataDTO.getTableType())) {
                    AssetsCheckUpdateVO assetsUpdate = assetsCheckUpdateMapper.findByIdFlowNo(auditDataDTO.getFlowNo());

                    Assets assets = new Assets();
                    assets.setId(assetsUpdate.getAssetId());
                    if (!StringUtils.isEmpty(assetsUpdate.getPlace())) {
                        assets.setPlace(assetsUpdate.getPlace());
                    }
                    if (!StringUtils.isEmpty(assetsUpdate.getAssetName())) {
                        assets.setName(assetsUpdate.getAssetName());
                    }
                    if (!StringUtils.isEmpty(assetsUpdate.getQrCode())) {
                        assets.setQrCode(assetsUpdate.getQrCode());
                    }
                    assetsMapper.updateById(assets);
                    if (!StringUtils.isEmpty(assetsUpdate.getImageUrl())) {
                        imagesMapper.updateConnectByAssetsId(assetsUpdate.getImageUrl(), assetsUpdate.getAssetId());
                    }
                }
            } else {
                System.out.println("不是最后一个审批人");
                int j = 0;
                int i = 0;
                while (true) {
                    if (i >= users.length) {
                        break;
                    } else if (String.valueOf(auditDataDTO.getApplicant()).equals(users[i])) {
                        j = i;
                        break;
                    } else {
                        i++;
                    }
                }
                this.auditFlowDetailMapper.updateAuditStatus(new AuditFlowDetail().setFlowNo(auditDataDTO.getFlowNo()).setReviewer(auditDataDTO.getApplicant()).setRemark(auditDataDTO.getOpinion()).setAuditStatus(Integer.valueOf(AuditStatusEnum.ADOPT.getIndex())).setSignatureUrl(auditDataDTO.getSignatureUrl()).setAuditTime(DateUtil.now()));
                this.auditFlowDetailMapper.updateAuditStatus(new AuditFlowDetail().setFlowNo(auditDataDTO.getFlowNo()).setReviewer(Integer.valueOf(Integer.parseInt(users[j + 1]))).setAuditStatus(Integer.valueOf(AuditStatusEnum.FORMYAPPROVAL.getIndex())));
            }
        } else if (auditDataDTO.getAppStatus().equals(3)) {
            this.auditFlowDetailMapper.updateAuditStatus(new AuditFlowDetail().setFlowNo(auditDataDTO.getFlowNo()).setReviewer(auditDataDTO.getApplicant()).setRemark(auditDataDTO.getOpinion()).setAuditStatus(Integer.valueOf(AuditStatusEnum.REFUSE.getIndex())).setSignatureUrl(auditDataDTO.getSignatureUrl()).setAuditTime(DateUtil.now()));
            this.auditFlowDetailMapper.deleteByFlowNoAndId(auditDataDTO.getFlowNo(), 4);
            this.auditFlowMapper.updateAppStatus(new AuditFlow().setFlowNo(auditDataDTO.getFlowNo()).setAppStatus(3).setCreateTime(DateUtil.now()));
        }
        //审批意见存如数据库
        Integer count = approvalUseContentMapper.update(auditDataDTO.getApplicant(), auditDataDTO.getOpinion());
        if (count == 0) {
            approvalUseContentMapper.add(auditDataDTO.getApplicant(), auditDataDTO.getOpinion());
        }
    }

    public PageInfo queryAudit(int pageNum, int pageSize, Integer userId, Integer status, String tableType, Integer applicant) {
        PageHelper.startPage(pageNum, pageSize);
        List<AuditFlowTODoVO> list = this.auditFlowMapper.queryAudit(userId, status, tableType, applicant);
        for (AuditFlowTODoVO auditFlowTODoVO : list) {
            AuditFlow auditFlow = this.auditFlowMapper.queryById(auditFlowTODoVO.getId());
            auditFlowTODoVO.setTableId(this.auditFlowMapper.queryIdByflowNo(auditFlow.getTableType(), auditFlow.getFlowNo()));
            if (auditFlowTODoVO.getTableType().equals("project") || auditFlowTODoVO.getTableType().equals("tender") || auditFlowTODoVO.getTableType().equals("contract") || auditFlowTODoVO.getTableType().equals("completed") || auditFlowTODoVO.getTableType().equals("settlement") || auditFlowTODoVO.getTableType().equals("final_statement") || auditFlowTODoVO.getTableType().equals("unit_information") || auditFlowTODoVO.getTableType().equals("project_assets_business") || auditFlowTODoVO.getTableType().equals("purchase_assets_business")) {
                auditFlowTODoVO.setProjectName(this.projectMapper.findByProjectNo(auditFlowTODoVO.getProjectNo()));
            }
            if (auditFlowTODoVO.getTableType().equals("contract") || auditFlowTODoVO.getTableType().equals("completed") || auditFlowTODoVO.getTableType().equals("settlement") || auditFlowTODoVO.getTableType().equals("final_statement") || auditFlowTODoVO.getTableType().equals("project_assets_business") || auditFlowTODoVO.getTableType().equals("purchase_assets_business")) {
                Section section = this.sectionMapper.selectById(auditFlowTODoVO.getSectionId());
                if (!StringUtils.isEmpty(section)) {
                    auditFlowTODoVO.setSectionName(section.getSectionName());
                }
            }
            if (auditFlowTODoVO.getTableType().equals("qr_code_generated")) {
                QrCodeGeneratedVO qrCodeGeneratedVO = this.qrCodeGeneratedMapper.selectByflowNo(auditFlow.getFlowNo());
                if (!StringUtils.isEmpty(qrCodeGeneratedVO)) {
                    auditFlowTODoVO.setProjectName(qrCodeGeneratedVO.getBuildName());
                    auditFlowTODoVO.setSectionName(qrCodeGeneratedVO.getSectionName());
                }
            }
            if (auditFlowTODoVO.getTableType().equals("daily_project") && !StringUtils.isEmpty(auditFlowTODoVO.getProjectNo())) {
                DailyProject dailyProject = this.dailyProjectMapper.findById(Integer.valueOf(Integer.parseInt(auditFlowTODoVO.getProjectNo())));
                if (!StringUtils.isEmpty(dailyProject)) {
                    auditFlowTODoVO.setProjectName(dailyProject.getProjectName());
                }
            }
        }
        return new PageInfo(list);
    }

    public CommonResult queryCount(Integer userId) {
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("noAuditFlowCount", (Object) Integer.valueOf(this.auditFlowMapper.queryAudit(userId, 2, null, null).size()));
            jsonObject.put("unReadCount", (Object) this.noticeAfficheMapper.queryCount(2, userId, 0));
            return new CommonResult().success(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            return new CommonResult().validateFailed(e.toString());
        }
    }

    public AuditFlow queryById(Integer id) {
        AuditFlow auditFlow = this.auditFlowMapper.queryById(id);
        Integer tableId = this.auditFlowMapper.queryIdByflowNo(auditFlow.getTableType(), auditFlow.getFlowNo());
      /*  if ("repair_jc".equals(auditFlow.getTableType()) || "repair_zn".equals(auditFlow.getTableType())) {
            RepairVO repairVO = this.repairMapper.queryById(tableId);
            auditFlow.setUserId(repairVO.getOrderUserId());
            auditFlow.setUserName(repairVO.getOrderUserName());
        }*/
        if ("repair".equals(auditFlow.getTableType())) {
            RepairVO repairVO = this.repairMapper.queryById(tableId);
            auditFlow.setUserId(repairVO.getOrderUserId());
            auditFlow.setUserName(repairVO.getOrderUserName());
        }
        return auditFlow.setTableId(tableId);
    }

    public List<AuditFlowDetail> queryByFlowNo(String flowNo, String tableType) {
        AuditFlowDetail auditFlowDetail = new AuditFlowDetail();
        auditFlowDetail.setFlowNo(flowNo);
        return this.auditFlowDetailMapper.queryAll(auditFlowDetail);
    }

    public Integer add(Integer userId, String flowNo, String now, String title, String tableType, String projectNo, Integer sectionId) {
        return Integer.valueOf(this.auditFlowMapper.insert(new AuditFlow()
                .setFlowNo(flowNo)
                .setTitle(title)
                .setTableType(tableType)
                .setApplicant(userId)
                .setCreateTime(now).setAppStatus(0)
                .setProjectNo(projectNo)
                .setSectionId(sectionId)));
    }

    public Integer addYouKe(Integer userId, String flowNo, String now,
                            String title, String tableType,
                            String projectNo, Integer sectionId, Integer approvalStepsId) {
        return Integer.valueOf(this.auditFlowMapper.insertYouKe(new AuditFlow()
                .setFlowNo(flowNo)
                .setTitle(title)
                .setTableType(tableType)
                .setApplicant(userId)
                .setCreateTime(now)
                .setAppStatus(1)
                .setProjectNo(projectNo)
                .setSectionId(sectionId)
                .setApprovalStepsId(sectionId)));
    }
}